import services
from services import BasicService
from filecrawler import *

class FileCrawlerService(BasicService, FileCrawler):
    def __init__(self, debug = False):
        BasicService.__init__(self)
        FileCrawler.__init__(self, debug)

    def process_command(self, command, args):
        obj = args[0]

        if command == "crawl":
            FileCrawler.crawl(self, obj)
            return True

        return "null"

    def crawl(self, path_to_crawl):
        return self.execute("crawl",(path_to_crawl,), block = False)

    def post(self, parent_path, child_path):
        FileCrawler.post(self, parent_path, child_path)
        if self.debug:
            print child_path, "added to crawl queue"
        self.result(child_path)
        self.crawl(child_path)

if __name__ == "__main__":
    file_crawler_service = FileCrawlerService(True)
    services.launch_service(file_crawler_service, "crawlerservice")
